//
//  HBHMainIconCell.m
//  HubeiHotel
//
//  Created by 张露杰 on 17/11/14.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "HBHMainIconCell.h"
#import "HBHMainIcon.h"
#import "TopBottomView.h"
@implementation HBHMainIconCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    //    继承父类
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
    }
    return self;
}

-(void)loadCellWithIcons:(NSArray *)icons
{
    //    重新布局
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    NSMutableArray *arrs = icons.mutableCopy;
    for (NSDictionary *icon in arrs) {
        if (!icon[@"id"]) {
            [arrs removeObject:icon];
            break;
        }
    }
    icons = arrs;
    
    for (int i = 0; i < icons.count; i++) {
        HBHMainIcon *icon = [[HBHMainIcon alloc]initWithFrame:CGRectMake(i%4*(SCREENW/4), 15*screenW_6 + i/4*68*screenW_6, 0, 0) data:icons[i] index:i HangNumber:4 Height:5*screenW_6 complete:^(NSInteger index) {
            if (_chooseMainBtnBlock) {
                self.chooseMainBtnBlock(index);
            }
        }];
     
        [self.contentView addSubview:icon];
    }
}

-(void)loadCellWithThreeIcons:(NSMutableArray *)icons{
    //    重新布局
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    NSMutableArray *arrs = icons.mutableCopy;
    for (NSDictionary *icon in arrs) {
        if (!icon[@"id"]) {
            [arrs removeObject:icon];
            break;
        }
    }
    icons = arrs;
    
    for (int i = 0; i < icons.count; i++) {
        HBHMainIcon *icon = [[HBHMainIcon alloc]initWithFrame:CGRectMake(i%4*(SCREENW/4), 15*screenW_6 + i/4*68*screenW_6, 0, 0) data:icons[i] index:i HangNumber:4 Height:5*screenW_6 Type:1 complete:^(NSInteger index) {
            if (_chooseMainBtnBlock) {
                self.chooseMainBtnBlock(index);
            }
        }];
        
        [self.contentView addSubview:icon];
    }
    
    NSInteger num = (icons.count - 1)/4 + ((icons.count - 1)%4?1:0);
    
    if (icons.count > 0) {
        for (int i = 0; i < 3; i++) {
            UIView *linex = [[UIView alloc]initWithFrame:CGRectMake((i+1)*(SCREENW - 6)/4, 0, 2, (int)(icons.count/4)*68*screenW_6 + 15*screenW_6)];
            linex.backgroundColor = backColor;
            [self.contentView addSubview:linex];
        }
        if (num < 10) {
            for (int i = 0; i < num - 1; i++) {
                UIView *liney = [[UIView alloc]initWithFrame:CGRectMake(0, (i+1)*(68*screenW_6 - 2) + 15*screenW_6, SCREENW, 2)];
                liney.backgroundColor = backColor;
                [self.contentView addSubview:liney];
            }
        }
    }
}

-(void)loadCellWithHomeIcons:(NSMutableArray *)icons{
    //    重新布局
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    
    NSMutableArray *arrs = icons.mutableCopy;
    for (NSDictionary *icon in arrs) {
        if (!icon[@"id"]) {
            [arrs removeObject:icon];
            break;
        }
    }
    icons = arrs;
    
    for (int i = 0; i < icons.count; i++) {
        HBHMainIcon *icon = [[HBHMainIcon alloc]initWithFrame:CGRectMake(i%5*(SCREENW/5), 15*screenW_6 + i/5*68*screenW_6, 0, 0) data:icons[i] index:i HangNumber:5 Height:5*screenW_6 complete:^(NSInteger index) {
            if (_chooseMainBtnBlock) {
                self.chooseMainBtnBlock(index);
            }
        }];
        [self.contentView addSubview:icon];
    }
}

-(void)loadJIuDianCellWithIcons:(NSArray *)icons
{
    //    重新布局
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    int widthNumber = (int)icons.count/2;
    for (int i = 0; i < icons.count; i++) {
        HBHMainIcon *icon = [[HBHMainIcon alloc]initWithFrame:CGRectMake(i%widthNumber*(SCREENW/widthNumber), 15*screenW_6 + i/widthNumber*68*screenW_6, 0, 0) data:icons[i] index:i HangNumber:widthNumber  Height:10*screenW_6 complete:^(NSInteger index) {
          
            if (_chooseMainBtnBlock) {
                self.chooseMainBtnBlock(index);
            }
        }];
        [self.contentView addSubview:icon];
    }
}

-(void)loadFangCellWithIcons:(NSArray *)icons
{
    //    重新布局
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    self.backgroundColor = backColor;
    
    int widthNumber = 4;
    for (int i = 0; i < icons.count; i++) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i%widthNumber*((SCREENW-7.5*screenW_6)/widthNumber+2.5*screenW_6), 5*screenW_6 + i/widthNumber*82.5*screenW_6,(SCREENW-7.5*screenW_6)/4,80*screenW_6)];
        view.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:view];
        
        HBHMainIcon *icon = [[HBHMainIcon alloc]initWithFrame:CGRectMake(0,12*screenW_6,0,0) data:icons[i] index:i HangNumber:widthNumber  Height:10*screenW_6 complete:^(NSInteger index) {
            NSLog(@"click on %ld",index);
            if (_chooseMainBtnBlock) {
                self.chooseMainBtnBlock(index);
            }
        }];
        [view addSubview:icon];
    }
}

-(void)loadTopDownCellWithIcons:(NSArray *)icons
{
    //    重新布局
    for (UIView *view in self.contentView.subviews) {
        [view removeFromSuperview];
    }
    self.backgroundColor = backColor;
    
    int widthNumber = 4;
    for (int i = 0; i < icons.count; i++) {
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i%widthNumber*((SCREENW-7.5*screenW_6)/widthNumber+2.5*screenW_6), 5*screenW_6 + i/widthNumber*82.5*screenW_6,(SCREENW-7.5*screenW_6)/4,80*screenW_6)];
        view.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:view];
        
        TopBottomView *icon = [[TopBottomView alloc]initWithFrame:CGRectMake(0,12*screenW_6,0,0) data:icons[i] index:i HangNumber:widthNumber  Height:0*screenW_6 complete:^(NSInteger index) {
            NSLog(@"click on %ld",index);
            if (_chooseMainBtnBlock) {
                self.chooseMainBtnBlock(index);
            }
        }];
        [view addSubview:icon];
    }
}



@end
